import { combineReducers, AnyAction } from "redux"
import * as actionTypes from './constants'

const initalState = {
    loading: true,
    home:{
        tabicons: [],
        rankLike:[],
        keypointsList:[],
        cityList:[],
        relationList:[],
    },
    homedatail :{
        inputValue:"风景真好看呀",
        list:[],
        swiperList : [],
        relevantList:[],
    }
}

const loadingReducer = (state = initalState.loading,
         action:AnyAction) => {
    switch(action.type) {
        case actionTypes.CHANGES_LOADING:
            return action.data
        default:
            return state
    }
}
const homeReducer = (state = initalState.home, action: AnyAction) => {
    switch(action.type) {
        case actionTypes.Tab_ICONS:
            return {
                ...state,
                tabicons: action.data
            }    
        break;
        case actionTypes.CHNAGE_RANK_LIKE:
            return {
                ...state,
                rankLike:action.data
            }
        break;
        case actionTypes.CHANGE_KEYPOINTS:
            return {
                ...state,
                keypointsList:action.data
            }
        case actionTypes.CHANGE_RELATION:
            return {
                ...state,
                relationList:action.data
            }
        case actionTypes.CHANGE_CITY:
            return {
                ...state,
                cityList:action.data
            }
        default:
            return state
    }
}
const detailReducer = (state = initalState.homedatail ,action: AnyAction) => {
    switch (action.type) {
        case actionTypes.CHANGE_INPUT_VALUE:
            // return action.data
            let newState = JSON.parse(JSON.stringify(state))
            newState.list.push(action.data);
            return newState;
            break;
        case actionTypes.CHANGE_SWIPER:
            return {
                ...state,
                swiperList:action.data
            }
            break;
        case actionTypes.CHANGE_RELEVANT:
            return {
                ...state,
                relevantList:action.data
            }
        default:
            return state
    }
}
export default combineReducers({
    loading: loadingReducer,
    home: homeReducer,
    homedetail: detailReducer,
})